Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / docs / source / Direct.html (Case Conflict 1)
1 <html>\r
2 <head>\r
3   <title>The source code</title>\r
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
6 </head>\r
7 <body  onload="prettyPrint();">\r
8     <pre class="prettyprint lang-js">Ext.onReady(function(){\r
9     Ext.Direct.addProvider(\r
10         Ext.app.REMOTING_API,\r
11         {\r
12             type:'polling',\r
13             url: 'php/poll.php'\r
14         }\r
15     );\r
16 \r
17     var out = new Ext.form.DisplayField({\r
18         cls: 'x-form-text',\r
19         id: 'out'\r
20     });\r
21 \r
22     var text = new Ext.form.TextField({\r
23         width: 300,\r
24         emptyText: 'Echo input'\r
25     });\r
26 \r
27     var call = new Ext.Button({\r
28         text: 'Echo',\r
29         handler: function(){\r
30             TestAction.doEcho(text.getValue(), function(result, e){\r
31                 var t = e.getTransaction();\r
32                 out.append(String.format('<p><b>Successful call to {0}.{1} with response:</b><xmp>{2}</xmp></p>',\r
33                        t.action, t.method, Ext.encode(result)));\r
34                 out.el.scroll('b', 100000, true);\r
35             });\r
36         }\r
37     });\r
38 \r
39     var num = new Ext.form.TextField({\r
40         width: 80,\r
41         emptyText: 'Multiply x 8',\r
42         style:  'text-align:left;'\r
43     });\r
44 \r
45     var multiply = new Ext.Button({\r
46         text: 'Multiply',\r
47         handler: function(){\r
48             TestAction.multiply(num.getValue(), function(result, e){\r
49                 var t = e.getTransaction();\r
50                 if(e.status){\r
51                     out.append(String.format('<p><b>Successful call to {0}.{1} with response:</b><xmp>{2}</xmp></p>',\r
52                         t.action, t.method, Ext.encode(result)));\r
53                 }else{\r
54                     out.append(String.format('<p><b>Call to {0}.{1} failed with message:</b><xmp>{2}</xmp></p>',\r
55                         t.action, t.method, e.message));\r
56                 }\r
57                 out.el.scroll('b', 100000, true);\r
58             });\r
59         }\r
60     });\r
61 \r
62     text.on('specialkey', function(t, e){\r
63         if(e.getKey() == e.ENTER){\r
64             call.handler();\r
65         }\r
66     });\r
67 \r
68         num.on('specialkey', function(t, e){\r
69         if(e.getKey() == e.ENTER){\r
70             multiply.handler();\r
71         }\r
72     });\r
73 \r
74         var p = new Ext.Panel({\r
75         title: 'Remote Call Log',\r
76         //frame:true,\r
77                 width: 600,\r
78                 height: 300,\r
79                 layout:'fit',\r
80                 \r
81                 items: [out],\r
82         bbar: [text, call, '-', num, multiply]\r
83         }).render(Ext.getBody());\r
84 \r
85     Ext.Direct.on('message', function(e){\r
86         out.append(String.format('<p><i>{0}</i></p>', e.data));\r
87                 out.el.scroll('b', 100000, true);\r
88     });\r
89 });\r
90 </pre>    \r
91 </body>\r
92 </html>